const { BaseBehavior, COMPONENT_OPTIONS } = require('../../mixins/component');
const { getPublicCoupon } = require('../../api/market');
const { tipError, tipSuccess } = require('../../common/platform');
const { getUserInfo, setUserInfo } = require('../../biztools/info');
const { userBindMobileWechat } = require('../../api/member');

Component({
    behaviors: [BaseBehavior],
    options: {
        ...COMPONENT_OPTIONS,
    },
    properties: {
        couponInfo: {
            type: Object,
            value: {},
        },
    },
    data: {
        memberInfo: getUserInfo(),
    },
    methods: {
        // 领劵
        async handleGetCoupon() {
            const { couponInfo } = this.data;
            console.log('CouponRowItem => 领取优惠券', couponInfo);
            await getPublicCoupon(couponInfo.id);
            // flag ? tipSuccess('领取成功') : tipError('领取失败');
        },
        // 绑定手机号
        async getUserPhoneNumber(e) {
            const { iv, encryptedData } = e.detail;
            const memberInfo = await userBindMobileWechat(iv, encryptedData);
            setUserInfo(memberInfo);
            this.setData({
                memberInfo,
            });
            await this.handleGetCoupon();
        },
    }
})
